{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item">
                            <div class="layui-input-inline layui-form">
                                <select name="role" id="role" lay-search="" class="layui-input">
                                    <option  value="">不限角色</option>
                                    <option  value="1">入库员</option>
                                    <option  value="2">库管员</option>
                                </select>
                            </div>
                            <div class="layui-input-inline layui-form">
                                <select name="userFrom" id="userFrom" lay-search="" class="layui-input">
                                    <option  value="">不限用户来源</option>
                                    <option  value="1">用户注册</option>
                                    <option  value="2">后台指定</option>
                                </select>
                            </div>
                            <div class="layui-input-inline layui-form">
                                <select name="department" lay-search="" class="layui-input">
                                    <option  value="">不限部门</option>
                                    {foreach name="data" item="vo"}
                                    <option  value="{$vo.department_id}">{$vo.department_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                            <div class="layui-col-md6 layui-input-inline">
                                <input type="text" id="key" class="layui-input search" name="key" value="" placeholder="用户名/手机号/职务"/>
                            </div>
                            <div class="layui-input-inline">
                                <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                                <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                            </div>
                        </div>
                </div>
                <!--搜索框结束-->
                <!--操作框开始-->
                <div class="col-sm-12">
                    <div class="input-group" >
                        <button class="btn btn-primary" type="button" onclick="wk.href('{:url('memberAdd')}');">
                            <i class="fa fa-plus"></i> 添加用户
                        </button>
                        <button class="btn btn-primary m-l-xs layuiBtn" data-type="excelAll" type="button" >
                            <i class="fa fa-print"></i> 导出用户
                        </button>
                    </div>
                </div>
                <!--操作框结束-->
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="demo"></table>
                    <!--状态模板-->
                    <script type="text/html" id="staBar">
                        {{# if(d.id!==1){ }}
                        <input type="checkbox" value="{{d.user_id}}"  lay-skin="switch"  lay-text="正常|冻结" lay-filter="OnOff"{{ d.user_status == 1 ? 'checked' : '' }}  >
                        {{# } }}
                    </script>
                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        <a href="javascript:;" onclick="wk.href('{:url('memberEdit')}?id={{d.user_id}}')" class="btn btn-primary btn-xs m-r-xs" title="编辑"><i class="fa fa-pencil"></i></a>
                        <a href="javascript:;" onclick="wk.confirm('{{d.user_id}}','{:url('memberDel')}')" class="btn btn-danger btn-xs m-r-xs" title="删除"><i class="fa fa-trash-o"></i></a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
        , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("appuser/index")}'
            ,response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
                {type: 'checkbox', fixed: 'left',}
                , {type:'numbers', width: 80, title: '序号'}
                , {field: 'user_username', width: '', title: '用户名', align: 'center'}
                , {field: 'user_phone', width: '', title: '手机号', align: 'center'}
                , {field: 'department_name', width: '', title: '部门', align: 'center'}
                , {field: 'user_zhiwei', width: '', title: '职务', align: 'center'}
                , {field: 'user_role', width: '', title: '角色', align: 'center',templet:"<div>{{ d.user_role == 1? '入库员' : '库管员' }}</div>"}
                , {field: 'user_where', width: '', title: '属性', align: 'center',templet:"<div>{{ d.user_where == 1? '前台注册' : '后台指定' }}</div>"}
               , {field: 'user_status',fixed: 'right', width: 100, title: '状态',sort: true, align: 'center', templet: '#staBar'}
               , {fixed: 'right', width: 100, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
        });
        //监听状态开关操作
        form.on('switch(OnOff)', function (obj) {
            var num = '';
            obj.elem.checked == true? num = 1: num = 2;
            //用户状态
            wk.status(this.value,num, '{:url("memberState")}',obj);
        });

        //批量操作
        var $ = layui.$, active = {
            excelAll: function(){
                //导出Excel
                wk.excelAll(getIds(),$('.layui-input').serialize(),"{:url('excelMember')}");
            }
        };
        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                ,data = checkStatus.data;
            $.each(data,function(index,item){
                ids.push(item['user_id'])
            });
            return ids;
        }
    });
</script>
</body>
</html>